#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include <unistd.h>

#define PORT 		9000
#define IPADDRESS	"127.0.0.100"

int main(int argc, char ** argv)
{
	int z;		//status return code
	int sck_inet;	//fd for socket
	struct sockaddr_in adr_inet;		// sockat address
	int len_inet;

	// create ipv4 socket
	sck_inet = socket(AF_INET, SOCK_STREAM, 0);
	if(sck_inet == -1) {
		perror("socket()");
		exit(1);
	}

	memset(&adr_inet, 0, sizeof(adr_inet));
	adr_inet.sin_family = AF_INET;
	adr_inet.sin_port = htons(PORT);
	inet_aton(IPADDRESS, &adr_inet.sin_addr);

	len_inet = sizeof(adr_inet);

	//bind socket
	z = bind(sck_inet, (struct sockaddr *) &adr_inet, len_inet);
	if(z == -1) {
		perror("bind()");
		exit(1);
	}

	listen(sck_inet, 6);

	//display socket
	system("netstat -pa --tcp 2>/dev/null | sed -n '1,/Proto/p;/bind/p'");

	close(sck_inet);

	return 0;
}
